package com.zmn.oms.dubbo.impl.zmn.normal.report;

import org.apache.dubbo.config.annotation.Service;
import com.zmn.common.dto.KvDTO;
import com.zmn.common.dto.ResponseDTO;
import com.zmn.common.utils.reflect.BeanMapper;
import com.zmn.common.utils.response.ResponseUtil;
import com.zmn.oms.common.exception.OmsBaseException;
import com.zmn.oms.dubbo.dto.zmn.report.GD114DIO;
import com.zmn.oms.dubbo.dto.zmn.report.GD114DTO;
import com.zmn.oms.dubbo.dto.zmn.report.NewOrderCountDIO;
import com.zmn.oms.dubbo.interfaces.zmn.normal.report.ZsNormalWorkReportRemoteService;
import com.zmn.oms.dubbo.utils.DubboConsts;
import com.zmn.oms.model.entity.report.GD114;
import com.zmn.oms.model.entity.report.GD114Query;
import com.zmn.oms.model.entity.report.newOrderCountQuery;
import com.zmn.oms.services.interfaces.report.WorkReportService;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Service(loadbalance = "roundrobin", timeout = 5000, retries = 2, version = DubboConsts.INTERFACE_VERSION, validation = "false")
public class ZsNormalWorkReportRemoteServiceImpl implements ZsNormalWorkReportRemoteService {
    @Resource
    WorkReportService workReportService;

    @Override
    public ResponseDTO<KvDTO<Integer, Integer>> getNewOrderCount(NewOrderCountDIO newOrderCountDIO) {
        if (Objects.isNull(newOrderCountDIO)) {
            return ResponseUtil.responseFail("查询条件不能为空");
        }
        newOrderCountQuery orderCountQuery = BeanMapper.map(newOrderCountDIO, newOrderCountQuery.class);
        ArrayList<KvDTO<Integer, Integer>> newOrderCount = workReportService.getNewOrderCount(orderCountQuery);
        return ResponseUtil.responseSuccessItems(newOrderCount);
    }

    @Override
    public ResponseDTO<GD114DTO> getGD114Report(GD114DIO gd114DIO) {
        GD114Query query = BeanMapper.map(gd114DIO, GD114Query.class);
        try {
            List<GD114> gd114s = workReportService.listGD114ReportByQuery(query);
            List<GD114DTO> gd114DTOS = gd114s.stream()
                    .map(gd114 -> new GD114DTO(gd114.getName(), gd114.getSpecialSeat(), gd114.getWechatPublicAccount()))
                    .collect(Collectors.toList());
            return ResponseUtil.responseSuccessItems(gd114DTOS);
        } catch (OmsBaseException e) {
            e.printStackTrace();
            return ResponseUtil.responseFail(e.getMessage());
        }
    }
}
